<?php
	header("Content-type:text/html;charset=utf8");
		//获取网页授权的token
		function httpGet($url) {
		    $curl = curl_init();
		    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		    curl_setopt($curl, CURLOPT_TIMEOUT, 500);
		    // 为保证第三方服务器与微信服务器之间数据传输的安全性，所有微信接口采用https方式调用，必须使用下面2行代码打开ssl安全校验。
		    // 如果在部署过程中代码在此处验证失败，请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
		    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
		//  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
		    curl_setopt($curl, CURLOPT_URL, $url);
		
		   	 $res = curl_exec($curl);
		   	 curl_close($curl);	
		
		    return $res;
   	 }	
		
	//var_dump("$_GET");
	if(!$_GET["openid"]){
	$appid="wx77266fec172b0620";
	$appsecret = "fbc98a7e7a2f129cc4712c62d9946873";
	$code = $_GET["code"];
	$api="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
	
	$json = httpGet($api);
	//var_dump(json_decode($json));
	
	$arr = json_decode($json,true);	
	//获取用户基本信息
	//获取网页授权的token
	$token = $arr["access_token"];
	//获取关注者的openid
	$openid = $arr["openid"];
	
	$api = "https://api.weixin.qq.com/sns/userinfo?access_token={$token}&openid={$openid}&lang=zh_CN";
	$json = httpGet($api);
	$userInfo = json_decode($json,true);	
	}else{
		$openid=$_GET["openid"];
	}
?>